<?php
include_once "common/basic.php";
if($_GET[a]=="follow" && $_GET[follower_uid] && $_GET[follow_uid]){
	echo $func->follow($_GET[follow_uid], $_GET[follower_uid]);
}else if($_GET[a]=="unfollow" && $_GET[follower_uid] && $_GET[follow_uid]){
	echo $func->unfollow($_GET[follow_uid], $_GET[follower_uid]);
}else if($_GET[a]=="incd" && $_GET[id]){
	echo $func->incResourceDownload($_GET[id]);
}else if($_GET[a]=="d_f" && $_GET[feed_id] && $_SESSION[uid]){//删除一条分享
	echo $func->feed_delete($_SESSION[uid],$_GET[feed_id]);
}else if($_GET[a]=='feed_com' && $_GET[feed_id]){
	$page = $_GET[page];
	if(!$page){
		$page = 1;
	}
	$pagesize=10;
	$total = $func->feed_comments_count($_GET[feed_id]);
	$comments = $func->feed_comments($_GET[feed_id],$page,$pagesize);
	if($comments && count($comments)>0){
		for($i=0;$i<count($comments);$i++){
			$comments[$i][publish_time]=$func->calc_publish_time($comments[$i][publish_time]);
			$comments[$i][my]=$comments[$i][uid]==$_SESSION[uid];
		}
	}
	$res = array('total'=>$total,'data'=>$comments,'page'=>$page,'pagesize'=>$pagesize);
	echo json_encode($res);

}else if($_GET[a]=='feed_com_add'){
	if($_GET[refer_id] && strlen($_GET[com])>0){
		if($_SESSION[uid]){
			$res = $func->feed_comment_add($_SESSION[uid],$_GET[refer_id],$_GET[com]);
			if($res){	
				echo 1;
			}else{
				echo "评论失败，请稍后再试";
			}
		}else{
			echo "请先登录";
		}
	}else{
		echo "非法请求";
	}
}elseif($_GET[a]=='com_del'){
	if($_GET[id]){
		echo $func->feed_comment_delete($_GET[id],$_SESSION[uid]);
	}else{
		echo "评论不存在";
	}
}elseif($_GET[a]=='forward_add'){
	$res = array();
	if($_SESSION[uid]){
		if($_GET[refer_id]){
			$feed_id = $func->feed_forward_add($_SESSION[uid],$_GET[refer_id],trim($_GET[msg]));
			if($feed_id){
				$res[success]=true;
				$res[id]=$feed_id;
			}else{
				$res[success]=false;
				$res[error]="转发失败，请稍后再试";
			}
		}else{
			$res[success]=false;
			$res[error]="转发失败，请稍后再试";
		}
	}else{
		$res[success]=false;
		$res[error]="请先登录";
	}
	echo json_encode($res);
	die();
}elseif($_GET[a]=='vcode_get'){//创建注册登录时用的验证码
	echo $vcode = $func->vcode_make();
	die();
}else{
	echo "null";
}
?>